//
//  UserAccountTools.swift
//  WeiBo
//
//  Created by wukeng on 16/8/28.
//  Copyright © 2016年 wukeng. All rights reserved.
//

import UIKit

class UserAccountViewModel {
    //MARK:- 将类设计成单例
    static let single : UserAccountViewModel = UserAccountViewModel()
    var account : UserAccount?
    //MARK:- 计算属性
    var accountPath : String{
        //1、获取沙盒路径
        let accountPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask, true).first!
//        print((accountPath as NSString).stringByAppendingPathComponent("account.plist"))
        return (accountPath as NSString).stringByAppendingPathComponent("account.plist")
    }
    
    var isLogin : Bool {
        if account == nil {
            return false
        }
        guard let expiresDate = account?.expires_date else{
            return false
        }
        return expiresDate.compare(NSDate()) == NSComparisonResult.OrderedDescending
    }

        
    init(){
       account = NSKeyedUnarchiver.unarchiveObjectWithFile(accountPath) as? UserAccount
    }

}
